package zl.com.gz_2017029e;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import zl.com.gz_2017029e.adapter.Account;
import zl.com.gz_2017029e.adapter.AccountAdapter;

/**
 * Created by Administrator on 2019/1/8 0008.
 */

public class AccountFrame extends Fragment {
    private List<Account> accountList = new ArrayList<>();
    private RecyclerView recyclerView;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.account_manag_frame,container,false);
        initAccounts();
        recyclerView = (RecyclerView)view.findViewById(R.id.account_fag_recyclerview);
        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(manager);
        AccountAdapter adapter = new AccountAdapter(accountList);
        recyclerView.setAdapter(adapter);
//        batchTopUp();
        return view;
    }
    //加载RecyclerView视图
    private void initAccounts(){
        Account account1 = new Account(R.drawable.car_logo,"辽A10001","张三",73);
        accountList.add(account1);
        Account account2 = new Account(R.drawable.car_logo,"辽A10002","李四",23);
        accountList.add(account2);
        Account account3 = new Account(R.drawable.car_logo,"辽A10003","王五",27);
        accountList.add(account3);
        Account account4 = new Account(R.drawable.car_logo,"辽A10004","赵六",2);
        accountList.add(account4);
    }

    //批量充值
    private void batchTopUp(){
//        List<AccountAdapter.ViewHolder> accountList = new ArrayList<>();
        View view = recyclerView.findContainingItemView(recyclerView);
        TextView carPlate = view.findViewById(R.id.item_carPlate);
        Toast.makeText(getContext(),carPlate.getText().toString(),Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onResume() {
        super.onResume();
    }
}
